package lium.lbs.lbsim.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.buz.hjcdriver.bean.AResultBean
import com.buz.hjcdriver.bean.SelectBankListResultBean
import com.lmlibrary.bean.ResponseBean
import lium.lbs.lbsim.utils.callbck.DialogCallback
import lium.lbs.lbsim.utils.ToastUtils
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_bankadd.*
import lium.lbs.lbsim.R
class BankCardAddActivity : BaseActivity(){

    override fun getLayoutId(): Int { return R.layout.activity_bankadd  }
    var bankbean: SelectBankListResultBean?=null
    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("添加银行卡")
        addOnClickListeners(R.id.choosebank_layout,R.id.btn_submit)
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when(v!!.id){
            R.id.choosebank_layout ->{
                val intent = Intent(this, SelectBankListActivity::class.java)
                startActivityForResult(intent,11)
            }
            R.id.btn_submit -> {
                submit()
            }
        }
    }

   fun submit(){
       if (bankbean==null){
           ToastUtils.showToast("请选择银行")
           return
       }
       val param = HashMap<String, String>()
       param["memberName"]=memberName.text.toString()
       param["bankId"]=bankbean!!.id.toString()
       param["cardNum"]=cardNum.text.toString()
        postData("/member/saveBankcard",param, object : DialogCallback<ResponseBean<List<AResultBean>>>(this) {
        override fun onSuccess(response: Response<ResponseBean<List<AResultBean>>>) {
                ToastUtils.showToast(response.body().msg)
                finish()
            }
        })
    }
    override fun getNetWorkData() {
    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK) {
            if (data?.hasExtra("bean")!!){
                bankbean = data.getSerializableExtra("bean") as SelectBankListResultBean?
                name.text = bankbean?.name
            }
        }
    }

}